package com.sqtracker.recommender.repository;

import com.sqtracker.recommender.model.UserBehavior;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface UserBehaviorRepository extends MongoRepository<UserBehavior, String> {

    List<UserBehavior> findByUserId(String userId);

    List<UserBehavior> findByUserIdAndType(String userId, String type);

    List<UserBehavior> findByTorrentId(String torrentId);

    List<UserBehavior> findByUserIdAndTorrentId(String userId, String torrentId);

    List<UserBehavior> findByTimestampBetween(Date start, Date end);

    @Query(value = "{ 'userId': ?0 }", count = true)
    long countByUserId(String userId);

    @Query(value = "{ 'userId': ?0, 'type': ?1 }", count = true)
    long countByUserIdAndType(String userId, String type);

    List<UserBehavior> findByUserIdOrderByTimestampDesc(String userId);
}